<script type="text/javascript">
    $(document).ready(function () {
        $('#publishButton').click(function (e) {
            $('#frmNewPublication').submit();
        })
        
        $('.delete').click(function(e){
            e.preventDefault();
            $(this).parent().parent().hide('slow');
            $.ajax({
                url: $(this).attr('href'),
                error: function() {
                    alert("hay un error en el servicio de datos");
                    return false;
                },
                success: function(data) {
                }
            });
        })
    })
</script>
<style type="text/css">
    .comment{
        width: 600px;
        min-height: 50px;
        margin-left: 45px;
        margin-bottom: 10px;
        background-color: #F8F8F8;
        -moz-border-radius:10px;
        -webkit-border-radius:10px;
        padding: 10px;
        border-radius:10px;

    }
    .publication{
        font-size: 18px;
        min-height: 50px;
        margin-bottom: 10px;
        background-color: #F1F1F1;
        padding: 10px;
        -moz-border-radius:10px;
        -webkit-border-radius:10px;
        border-radius:10px;
    }
    a h5{
        margin-left: 45px;
        margin-bottom: 10px;
    }

</style>

<div class="content-box">

    <div class="content-header">
        <h3>Muro de <?php echo $this->friendUser->profile->name . " ," . $this->friendUser->profile->surname ?></h3>
    </div>
    <?php if ($this->permission != GroupPermission::READ): ?>
        <form id="frmNewPublication" action="/wall/newpublication/id_objetct_type/<?php echo $this->wall->object->id; ?>" method="POST">
            <h4> Escribe en su muro... </h4>
            <textarea style="width: 600px; height: 50px" name="publicationMessage"></textarea>
        </form>
    <?php endif; ?>
    <a href="javascript:void(0)" id="publishButton"><span><span>Publicar</span></span></a>

    <div id="publicationsList" class="divContainer">
        <?php if (count($this->publications) == 0): ?>
            <h2>No hay Publicaciones</h2>
        <?php endif;?>
        <?php foreach ($this->publications as $publication): ?>
            <h2>Publicaciones</h2>
            <div>
                <hr/>

                <?php if (($publication->object->user->id == $this->user->id) || UMbook_Manager::getUserAdminStatus()): ?>
                    <a href="/home/index/">
                        <h3>
                            <?php echo $publication->object->user->profile->name . ", " . $publication->object->user->profile->name . " Publicó:"; ?>
                        </h3>
                    </a>
                    <div class="publication">
                        <?php echo $publication->message ?>
                        <a style="float: right" class="delete" href="/wall/deletepublication/idPublication/<?php echo $publication->id ?>">X<a/>
                    </div>
                <?php else: ?>
                    <a href="/wall/index/idUser/<?php echo $publication->object->user->id ?>">
                        <h3>
                            <?php echo $publication->object->user->profile->name . ", " . $publication->object->user->profile->name . " Publicó:"; ?>
                        </h3>
                    </a>
                    <div class="publication">
                        <?php echo $publication->message ?>
                    </div>
                <?php endif; ?>






                <?php $subPublications = Publication::findAllByEntity($publication->object->id) ?>


                <?php foreach ($subPublications as $subPublication): ?>
                    <div>    
                        <?php if (($subPublication->object->user->id == $this->user->id) || UMbook_Manager::getUserAdminStatus()): ?>
                            <a href="/home/index">
                                <h5>
                                    <?php echo $subPublication->object->user->profile->name . ", " . $subPublication->object->user->profile->surname . " Comento:"; ?>
                                </h5>
                            </a>
                            <div class="comment">
                                <?php echo $subPublication->message ?>
                                <a style="float: right" class="delete" href="/wall/deletecomment/idPublication/<?php echo $subPublication->id ?>">X<a/>
                            </div>
                        <?php else: ?>
                            <a href="/wall/index/idUser/<?php echo $publication->object->user->id ?>">
                                <h5><?php echo $subPublication->object->user->profile->name . ", " . $subPublication->object->user->profile->name . " Comento:"; ?></h5>
                            </a>
                            <div class="comment"><?php echo $subPublication->message ?></div>
                        <?php endif; ?>
                    </div>
                <?php endforeach; ?>



                <?php if ($this->permission != GroupPermission::READ): ?>
                    <form id="frmNewSubPublication" class="comment" action="/wall/newpublication/id_objetct_type/<?php echo $publication->object->id; ?>" method="POST">
                        <textarea style="width: 580px; height: 35px" name="publicationMessage" ></textarea><br/>
                        <input type="submit" value="Publicar comentario"></input>
                    </form>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>

    </div>
</div>